
getMaxIdx <- function(x){
    w <- which(x==max(x))
    if(length(w)==1)
        {
            return(w)
        }else{
            return(-1)
        }  
}

t <- apply( XF , 1 , getMaxIdx )
t <- (unlist(t))
t[1:10]
runner <- 1:length(t)
t[t==-1]=runner[t==-1]
dd <- t-runner
idx <- (dd > 30 | dd < -30)
sum(idx)
runner <- runner[!idx]
dd <- dd[!idx]
plot(runner,dd,type="l")

t <- XF[1000:1020,1000:1020]
